package com.ruoyi.web.controller.schedule.task;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.system.domain.Assess;
import com.ruoyi.system.service.IAssessService;
import io.swagger.models.auth.In;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;


@Component
@EnableScheduling
public class ScheduleAssessStatusTask {

    private static final Logger log = LoggerFactory.getLogger(ScheduleAssessStatusTask.class);
    @Autowired
    private IAssessService assessService;

    /**
     * 每天执行一次，更新任务状态
     */
    @Scheduled(cron = "${schedule.assess-status-cron}")
    public void task() {
        log.info("更新任务状态开始");
        List<Integer> statusList = Arrays.asList(0, 1);
        List<Assess> assessList = assessService.selectAssessListByStatus(statusList);
        if (!assessList.isEmpty()) {
            for (Assess assess : assessList) {
                int status = assessService.determineTaskStatus(assess);
                assess.setStatus(status);
                assessService.updateAssess(assess);
            }
        }
        log.info("更新任务状态结束");
    }
}
